package com.leoncom.sms_silencer.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import com.leoncom.sms_silencer.SilencerActivity;
import com.leoncom.sms_sliencer.R;

public class NotifyManagerHelper {
	
	public static void notifyMessage(Context ctxt, CharSequence title, CharSequence content, int id) {
		NotificationManager nm = (NotificationManager)ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
		Notification notify = makeNotification(ctxt, title, content);
		nm.notify(id, notify);
	}
	
	public static void notifyInboxMessage(Context ctxt, CharSequence title, CharSequence content, int id, String[] lines) {
		NotificationManager nm = (NotificationManager)ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
		Notification notify = makeInboxNotification(ctxt, title, content, lines);
		nm.notify(id, notify);
	}

	private static Notification makeNotification(Context ctxt, CharSequence title,
			CharSequence content) {
		NotificationCompat.Builder mBuilder =
		        new NotificationCompat.Builder(ctxt)
		        .setSmallIcon(R.drawable.ic_launcher)
		        .setContentTitle(title)
		        .setContentText(content)
		        .setWhen(System.currentTimeMillis());

		Intent intent = new Intent(ctxt, SilencerActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(
				ctxt, 0, intent,
				Intent.FLAG_ACTIVITY_NEW_TASK);
		mBuilder.setContentIntent(contentIntent);
		return mBuilder.build();
	}
	
	private static Notification makeInboxNotification(Context ctxt, CharSequence title,
			CharSequence content, String[] lines) {
		NotificationCompat.Builder mBuilder =
		        new NotificationCompat.Builder(ctxt)
		        .setSmallIcon(R.drawable.ic_launcher)
		        .setContentTitle(title)
		        .setContentText(content)
		        .setWhen(System.currentTimeMillis());
		
		NotificationCompat.InboxStyle inboxStyle =
		        new NotificationCompat.InboxStyle();
		inboxStyle.setBigContentTitle("Mute task details:");
		for(int i = 0; i < lines.length; i++) {
			inboxStyle.addLine(lines[i]);
		}
		mBuilder.setStyle(inboxStyle);
		
		Intent intent = new Intent(ctxt, SilencerActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(
				ctxt, 0, intent,
				Intent.FLAG_ACTIVITY_NEW_TASK);
		mBuilder.setContentIntent(contentIntent);
		return mBuilder.build();
	}

}
